package com.pug.aspect;

import com.pug.pojo.KssUser;
import com.pug.dto.MessageDto;
import com.pug.service.message.MessageService;
import com.pug.service.user.UserServiceImpl;
import com.pug.utils.pwd.DesUtils;
import com.pug.vo.KssUserVo;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;


@Component
@Aspect
public class SaveLogonAspect {
    public SaveLogonAspect(){};
    @Resource
    MessageService messageService;
    @Resource
    UserServiceImpl userService;
    //切点
    @Pointcut("@annotation(com.pug.annotation.SaveLogonMessage)")
    public void SaveLogonPointcut(){

    }
//    @After(value = "SaveLogonPointcut()")
    @After(value = "SaveLogonPointcut()")
    public void  saveLogonMessage(JoinPoint point){
        Signature signature = point.getSignature();
        Object target = point.getTarget();
        MethodSignature methodSignature=(MethodSignature) signature;
        Object[] args = point.getArgs();
        KssUserVo userVo=(KssUserVo)args[0];
        KssUser kssUser=userService.getByPhone(DesUtils.encrypt(userVo.getPhone())); //后续去掉，因为这里目前前端好像加密有问题
        // 发送消息
//        MessageDto messageMo = new MessageDto();
//        messageMo.setTitle("注册通知");
//        messageMo.setMsgcontent("恭喜你【" + kssUser.getNickname() + "】加入到旅游平台，奖励积分50。");
//        messageMo.setMsgtype(1);
//        messageMo.setCreateTime(new Date());
//        messageMo.setNickname(kssUser.getNickname());
//        messageMo.setUserid(kssUser.getId() + "");
//        messageMo.setAvatar(kssUser.getAvatar());
//        messageMo.setIcon("/static/icon-item-001.png");
//        messageService.saveMessage(messageMo);
    }
}
